﻿using Microsoft.ExtendedReflection.ComponentModel;
using Microsoft.ExtendedReflection.Remote;

namespace MolesVS2012.Host.Agent
{
    internal sealed class MolesAgentRemotingManager : ComponentElementBase
    {
        private readonly string clientID;

        public string ClientID
        {
            get
            {
                return this.clientID;
            }
        }

        public MolesAgentRemotingManager(IComponent host)
            : base(host)
        {
            this.clientID = RemoteServer.RegisterClient((IServiceProvider)this.Host.Site, this.Host.GetService<MolesHostAdapterManager>().ServerChannel);
            this.Host.Log.LogMessage("Agent", "client {0} registered", new object[1]
      {
        (object) this.clientID
      });
        }

        public IRemoteClientConnector GetConnector()
        {
            return RemoteClient.GetConnector(this.Host.GetService<MolesHostAdapterManager>().ServerChannel, this.clientID);
        }

        public void Close()
        {
            this.Host.Log.LogMessage("Agent", "waiting for client {0}", new object[1]
      {
        (object) this.clientID
      });
            RemoteServer.WaitTillServerReady(this.clientID);
        }
    }
}
